/*
*  Copyright 2019-2023 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.poemmanager.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.poemmanager.domain.Comment;
import me.zhengjie.poemmanager.domain.vo.CommentQueryCriteria;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author hwl
* @date 2024-12-06
**/
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    IPage<Comment> findAll(@Param("criteria") CommentQueryCriteria criteria, Page<Object> page);

    List<Comment> findAll(@Param("criteria") CommentQueryCriteria criteria);

    @Select("select comment_id,content,object_id,object_type ,created_at from comment where user_name=#{userName}")
    List<Comment> getCommentByUserId(String userName);
    @Select("select count(*) from object_like where object_type=4 and object_id=#{commentId} ")
    Integer getCountLike(Integer commentId);
    @Select("select count(*) from comment where object_id=#{id} and object_type=#{i} ")
    Integer getCommentCount(Integer id, Integer i);

    @Select("select * from post_comment where object_id =#{id}")
    List<Comment>  getPostCommentByObjectId(Integer id);
    @Select("select * from poem_user_comment where object_id =#{id}")
    List<Comment>  getPoemUserCommentByObjectId(Integer id);
    @Select("select * from poem_poet_comment where object_id =#{id}")
    List<Comment>  getPoemPoetCommentByObjectId(Integer id);
    @Select("select * from recitation_comment where object_id =#{id}")
    List<Comment>  getRecitationCommentByObjectId(Integer id);

    //getTitle
    @Select("select title from post where post_id=#{objectId}")
    String getPostTitle(Integer objectId);
    @Select("select title from poem_user where poem_id=#{objectId}")
    String getPoemUserTitle(Integer objectId);
    @Select("select title from poem_poet where poem_id=#{objectId}")
    String getPoemPoetTitle(Integer objectId);
    @Select("select title from recitation where recitation_id=#{objectId}")
    String getRecitationTitle(Integer objectId);

    // 分页查询
    List<Comment> selectUserCommentsPage(@Param("userName") String userName,
                                         @Param("page") Page<Comment> page);

    // 查询总数
    Integer selectUserCommentsCount(@Param("userName") String userName);

}